package com.easy.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.Orders;
import com.easy.common.service.IOrdersService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("orders")
public class OrdersController {
    @Autowired
    IOrdersService ordersService;
    @PostMapping("/")
    public ResultData insert(@RequestBody Orders orders){
        Orders result=ordersService.insert(orders);
        return ResultData.success(result);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody Orders orders){
        return ResultData.success(ordersService.update(orders));
    }

    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id){
        return ResultData.success(ordersService.getByID(id));
    }
    @GetMapping("/userid")
    public ResultData getListByUserID(IPage page,@RequestBody Integer userid){
        IPage<Orders> data=ordersService.getListByUserID(page, userid);
        return ResultData.success(data);
    }
    @GetMapping("/customerid")
    public ResultData getListByCustomerID(IPage page,@RequestBody Integer customerid){
        IPage<Orders> data=ordersService.getListByCustomerID(page,customerid);
        return ResultData.success(data);
    }

}
